#Manuscript-Figure 1
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 0, xmax = 50, ymin = 0, ymax = 0.15)
mydata<-read.dta13(file="manuscript_figure_data.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo2, ymax=predhi2), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo20, ymax=predhi20), fill = "black", alpha=.5) +
  geom_line(aes(x=nosettleyr, y=pred2), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=nosettleyr, y=pred20), alpha =1, show_guide=F) +
  geom_vline(aes(xintercept=13), size = .5, color = "black", linetype="dashed") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(0, 50, 10), limits=c(0, 50)) +
  scale_y_continuous(breaks=seq(0, 0.15, .05), limits = c(0, 0.15))

plot1
ggsave(file="manuscript_figure.jpg", width=8, height=6)
ggsave(file="manuscript_figure.tiff", width=8, height=6, dpi=800)



#Appendix B.10 - Random Effects - Figure 1
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 0, xmax = 50, ymin = 0, ymax = 0.30)
mydata<-read.dta13(file="randomeffectsgraph.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo2, ymax=predhi2), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo20, ymax=predhi20), fill = "black", alpha=.5) +
  geom_line(aes(x=nosettleyr, y=pred2), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=nosettleyr, y=pred20), alpha =1, show_guide=F) +
  geom_vline(aes(xintercept=13), size = .5, color = "black", linetype="dashed") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(0, 50, 10), limits=c(0, 50)) +
  scale_y_continuous(breaks=seq(0, 0.30, .05), limits = c(0, 0.325))

plot1
ggsave(file="randomeffectsgraph.jpg", width=8, height=6)



#Appendix B.11 - Figure 1
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 0, xmax = 50, ymin = 0, ymax = 0.151)
mydata<-read.dta13(file="loggraphdata.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo2, ymax=predhi2), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=nosettleyr, ymin=predlo20, ymax=predhi20), fill = "black", alpha=.5) +
  geom_line(aes(x=nosettleyr, y=pred2), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=nosettleyr, y=pred20), alpha =1, show_guide=F) +
  geom_vline(aes(xintercept=13), size = .5, color = "black", linetype="dashed") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(0, 50, 10), limits=c(0, 50)) +
  scale_y_continuous(breaks=seq(0, 0.15, .05), limits = c(0, 0.151))

plot1
ggsave(file="loggraph.jpg", width=8, height=6)



#Appendix B.11 - Figure 2
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 0, xmax = 50, ymin = 0, ymax = 0.15)
mydata<-read.dta13(file="GAMpredictionsALL.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=nosettleyr, ymin=lo1, ymax=hi1), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=nosettleyr, ymin=lo, ymax=hi), fill = "black", alpha=.5) +
  geom_line(aes(x=nosettleyr, y=predprob1), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=nosettleyr, y=predprob), alpha =1, show_guide=F) +
  geom_vline(aes(xintercept=13), size = .5, color = "black", linetype="dashed") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(0, 50, 10), limits=c(0, 50)) +
  scale_y_continuous(breaks=seq(0, 0.15, .05), limits = c(0, 0.15))

plot1
ggsave(file="GAMgraph.jpg", width=8, height=6)



#Appendix B.12 - Figure 1 - China Pakistan Actual Data
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 1947, xmax = 1975, ymin = 0, ymax = 0.5)
mydata<-read.dta13(file="ChinaPakActualData.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=year, ymin=predlo2, ymax=predhi2), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=year, ymin=predlo20, ymax=predhi20), fill = "black", alpha=.5) +
  geom_line(aes(x=year, y=pred2), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=year, y=pred20), alpha =1, show_guide=F) +
  #geom_vline(aes(xintercept=1950), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1961), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1963), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1964), size = .5, color = "black", linetype="solid") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(1950, 1975, 5), limits=c(1947, 1975)) +
  scale_y_continuous(breaks=seq(0, 0.5, .1), limits = c(0, 0.5))

plot1
ggsave(file="ChinaPakActual.jpg", width=8, height=6)


#Appendix B.12 - Figure 2 - China Pakistan Smoothed Data
library(ggplot2)
library(gridExtra)
library(foreign)
library(readstata13)
rect <- data.frame(xmin = 1947, xmax = 1975, ymin = 0, ymax = 0.2)
mydata<-read.dta13(file="ChinaPakSmooth2.dta")
plot1 <- ggplot(mydata) +
  geom_hline(aes(yintercept=0), size = .5, color = "black") +
  #geom_rect(data = rect, aes(xmin = -10, xmax = 10, ymin=0, ymax = 2.0), fill = "gray", fill = "gray", alpha=1, inherit.aes=F) +
  geom_ribbon(aes(x=year, ymin=predlo2, ymax=predhi2), fill = "grey", alpha=.75) +
  geom_ribbon(aes(x=year, ymin=predlo20, ymax=predhi20), fill = "black", alpha=.5) +
  geom_line(aes(x=year, y=pred2), linetype="longdash", alpha =1, show_guide=F) +
  geom_line(aes(x=year, y=pred20), alpha =1, show_guide=F) +
  #geom_vline(aes(xintercept=1950), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1961), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1963), size = .5, color = "black", linetype="dashed") +
  geom_vline(aes(xintercept=1964), size = .5, color = "black", linetype="solid") +
  #theme(legend.position=c(.85, .20)) +
  theme_bw() +
  theme(legend.position="bottom", legend.title=element_blank()) +
  theme(text=element_text(size=16)) +
  labs(x = "Dyad Age (in Years)", y = "Predicted Probability of Border Settlement")  +
  scale_x_continuous(breaks=seq(1950, 1975, 5), limits=c(1947, 1975)) +
  scale_y_continuous(breaks=seq(0, 0.2, .05), limits = c(0, 0.2))

plot1
ggsave(file="ChinaPakSmooth.jpg", width=8, height=6)
